package easy

import "sort"

func MissingNumber(nums []int) int {
	sort.Ints(nums)
	for i, num := range nums {
		if num != i {
			return i
		}
	}
	return len(nums)
}

func MissingNumber1(nums []int) int {
	n := len(nums)
	total := n * (n + 1) / 2
	sum := 0
	for _, num := range nums {
		sum += num
	}
	return total - sum
}

func MissingNumber2(nums []int) int {
	has := map[int]bool{}
	for _, num := range nums {
		has[num] = true
	}
	for i := 0; ; i++ {
		if !has[i] {
			return i
		}
	}
}
